﻿using System.Windows.Forms;

namespace StreamBabyService
{
    public partial class BatOutput : Form
    {
        readonly Main _parentForm;

        /// <summary>
        /// Initializes a new instance of the <see cref="BatOutput"/> class.
        /// </summary>
        /// <param name="batoutput">The batoutput.</param>
        /// <param name="parentForm">The parent form.</param>
        /// <created on="5/13/2012" by="Dan Turco"/>
        public BatOutput( string batoutput, Main parentForm)
        {
            InitializeComponent();
            _parentForm = parentForm;
            txtOutput.Text = batoutput;
            ScrollBottom();
            timer1.Enabled = true;
        }

        /// <summary>
        /// Bats the output form closing.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.FormClosingEventArgs"/> instance containing the event data.</param>
        /// <created on="5/13/2012" by="Dan Turco"/>
        private void BatOutputFormClosing(object sender, FormClosingEventArgs e)
        {
            timer1.Enabled = false;
        }

        /// <summary>
        /// Timer1s the tick.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <created on="5/13/2012" by="Dan Turco"/>
        private void Timer1Tick(object sender, System.EventArgs e)
        {
            if (_parentForm != null)
            {
                try
                {
                    txtOutput.Text = _parentForm.Outputdata.ToString();
                    ScrollBottom();
                }catch
                {
                }
            }
        }

        /// <summary>
        /// Scrolls the bottom.
        /// </summary>
        /// <created on="5/13/2012" by="Dan Turco"/>
        private void ScrollBottom()
        {
            txtOutput.SelectionStart = txtOutput.Text.Length;
            txtOutput.ScrollToCaret();
        }
    }
}
